﻿using Microsoft.Practices.Unity;
using SampleServiceInterfacesAndImplementation;
using System;

namespace UnitySamples
{
    public class CustomerService
    {
        /*
         /*
         * As an example of constructor injection, if a class that developers 
         * instantiate using the Resolve method of the Unity container has a 
         * constructor that defines one or more dependencies on other classes, 
         * the Unity container automatically creates the dependent object 
         * instance specified in parameters of the constructor. 
         * For example, the following code shows a class named CustomerService 
         * that has a dependency on a class named LoggingService.
         * 
         */
        public CustomerService(ConsoleLogger myServiceInstance)
        {
            // work with the dependent instance
            myServiceInstance.Write("SomeValue ");
        }
    }

    public class Constructor_Injection
    {
        /*
         * At run time, developers create an instance of the CustomerService class 
         * using the Resolve method of the container, which causes the instance 
         * generation framework to inject an instance of the concrete class 
         * LoggingService within the scope of the CustomerService class.
         */
        public static void Sample()
        {
            //using unity
            IUnityContainer uContainer = new UnityContainer();
            CustomerService myInstance = uContainer.Resolve<CustomerService>();
            ////creating instance manually
            //CustomerService myInstanceManually = 
            //    new CustomerService
            //        (
            //            new ConsoleLogger()
            //        );
        }
    }
}